i18n and pt-BR translation on admin panel

jamesperet 9 years ago
parent
commit
09c4bdbc43

+ 1 - 0
Gemfile

@@ -45,6 +45,7 @@ gem 'figaro'
45 45
 gem "mini_magick"
46 46
 gem 'fog'
47 47
 gem "carrierwave"
48
+gem 'i18n'
48 49
 
49 50
 # Use ActiveModel has_secure_password
50 51
 # gem 'bcrypt', '~> 3.1.7'

+ 1 - 0
Gemfile.lock

@@ -198,6 +198,7 @@ DEPENDENCIES
198 198
   fog
199 199
   font-awesome-rails
200 200
   friendly_id (~> 5.0.0)
201
+  i18n
201 202
   jbuilder (~> 1.2)
202 203
   jquery-rails
203 204
   less-rails

+ 9 - 0
app/controllers/application_controller.rb

@@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base
3 3
   # For APIs, you may want to use :null_session instead.
4 4
   protect_from_forgery with: :exception
5 5
   
6
+  before_filter :set_locale
7
+  
6 8
   before_filter :configure_permitted_parameters, if: :devise_controller?
7 9
   
8 10
   def configure_permitted_parameters
@@ -10,4 +12,11 @@ class ApplicationController < ActionController::Base
10 12
     devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password) }
11 13
   end
12 14
   
15
+  private
16
+  
17
+    def set_locale
18
+      #I18n.config.enforce_available_locales = false
19
+      I18n.default_locale = "pt-BR"
20
+    end
21
+  
13 22
 end

+ 4 - 4
app/views/admin_panel/_sidebar_nav.html.erb

@@ -1,12 +1,12 @@
1 1
 <div class="span3" style="margin-top: 25px;">	
2 2
 	<ul class="nav nav-pills nav-stacked">
3 3
 	   <% if current_page?(:action => 'dashboard')%><li class="active"> <% else %><li><% end %>
4
-	   <%= link_to '<i class="icon-home icon-white"></i> Dashboard'.html_safe, admin_dashboard_path %></li>
4
+	   <%= link_to ('<i class="icon-home icon-white"></i> '+(t "admin_panel.dashboard")).html_safe, admin_dashboard_path %></li>
5 5
 	   <% if current_page?(:action => 'posts')%><li class="active"> <% else %><li><% end %>
6
-	   <%= link_to '<i class="icon-file icon-white"></i> Posts'.html_safe, admin_posts_path %></li>
6
+	   <%= link_to ('<i class="icon-file icon-white"></i> '+(t "admin_panel.posts")).html_safe, admin_posts_path %></li>
7 7
 	   <% if current_page?(:action => 'files')%><li class="active"> <% else %><li><% end %>
8
-	   <%= link_to '<i class="icon-file icon-white"></i> Files'.html_safe, admin_files_path %></li>
8
+	   <%= link_to ('<i class="icon-file icon-white"></i> '+(t "admin_panel.files")).html_safe, admin_files_path %></li>
9 9
 	   <% if current_page?(:action => 'users')%><li class="active"> <% else %><li><% end %>
10
-	   <%= link_to '<i class="icon-user icon-white"></i> Users'.html_safe, admin_users_path %></li>
10
+	   <%= link_to ('<i class="icon-user icon-white"></i> '+(t "admin_panel.users")).html_safe, admin_users_path %></li>
11 11
 	</ul>
12 12
 </div>

+ 5 - 5
app/views/admin_panel/dashboard.html.erb

@@ -2,19 +2,19 @@
2 2
 	<%= render 'admin_panel/sidebar_nav' %>
3 3
 	<div class="span9">
4 4
 		<div class="hero-unit">
5
-		  <h1>Dashboard</h1>
6
-		  <p>Welcome back <%= current_user.full_name%></p>
5
+		  <h1><%= t "admin_panel.dashboard" %></h1>
6
+		  <p><%= t "admin_panel.welcome" %> <%= current_user.full_name%></p>
7 7
 		</div>
8 8
 		<div class="well summary">
9 9
 			<ul>
10 10
 				<li>
11
-					<a href="<%= admin_users_path %>"><span class="count"><%= @users.length %></span> Users</a>
11
+					<a href="<%= admin_users_path %>"><span class="count"><%= @users.length %></span> <%= t "admin_panel.users" %></a>
12 12
 				</li>
13 13
 				<li>
14
-					<a href="<%= admin_files_path %>"><span class="count"><%= @files.length %></span> Files</a>
14
+					<a href="<%= admin_files_path %>"><span class="count"><%= @files.length %></span> <%= t "admin_panel.files" %></a>
15 15
 				</li>
16 16
 				<li class="last">
17
-					<a href="<%= admin_posts_path %>"><span class="count"><%= @posts.length %></span> Posts</a>
17
+					<a href="<%= admin_posts_path %>"><span class="count"><%= @posts.length %></span> <%= t "admin_panel.posts" %></a>
18 18
 				</li>
19 19
 			</ul>
20 20
 		</div>

+ 1 - 1
app/views/admin_panel/files.html.erb

@@ -2,7 +2,7 @@
2 2
 	<%= render 'admin_panel/sidebar_nav' %>
3 3
 	<div class="span9">
4 4
 		<div class="page-header">
5
-		  <h1>Files <%= link_to 'Upload File', new_upload_path, :class => 'btn btn-primary btn-mini' %></h1>
5
+		  <h1><%= t "admin_panel.files" %> <%= link_to (t "admin_panel.upload_file"), new_upload_path, :class => 'btn btn-primary btn-mini' %></h1>
6 6
 		</div>
7 7
 		<ul class="thumbnails">
8 8
 		    <% @uploads.each do |upload| %>

+ 1 - 1
app/views/admin_panel/posts.html.erb

@@ -2,7 +2,7 @@
2 2
 	<%= render 'admin_panel/sidebar_nav' %>
3 3
 	<div class="span9">
4 4
 		<div class="page-header">
5
-		  <h1>Blog Posts <%= link_to 'New Blog post', new_blog_post_path, :class => 'btn btn-primary btn-mini' %></h1>
5
+		  <h1><%= t "admin_panel.posts" %> <%= link_to (t "admin_panel.new_blog_post"), new_blog_post_path, :class => 'btn btn-primary btn-mini' %></h1>
6 6
 		</div>
7 7
 		<table class="table table-bordered">
8 8
 		  <thead>

+ 1 - 1
app/views/admin_panel/users.html.erb

@@ -2,7 +2,7 @@
2 2
 	<%= render 'admin_panel/sidebar_nav' %>
3 3
 	<div class="span9">
4 4
 		<div class="page-header">
5
-		  <h1>Users</h1>
5
+		  <h1><%= t "admin_panel.users" %></h1>
6 6
 		</div>
7 7
 		<table class="table table-bordered">
8 8
 		  <thead>

+ 211 - 22
config/locales/en.yml

@@ -1,23 +1,212 @@
1
-# Files in the config/locales directory are used for internationalization
2
-# and are automatically loaded by Rails. If you want to use locales other
3
-# than English, add the necessary files in this directory.
4
-#
5
-# To use the locales, use `I18n.t`:
6
-#
7
-#     I18n.t 'hello'
8
-#
9
-# In views, this is aliased to just `t`:
10
-#
11
-#     <%= t('hello') %>
12
-#
13
-# To use a different locale, set it with `I18n.locale`:
14
-#
15
-#     I18n.locale = :es
16
-#
17
-# This would use the information in config/locales/es.yml.
18
-#
19
-# To learn more, please read the Rails Internationalization guide
20
-# available at http://guides.rubyonrails.org/i18n.html.
21
-
22 1
 en:
23
-  hello: "Hello world"
2
+  date:
3
+    abbr_day_names:
4
+    - Sun
5
+    - Mon
6
+    - Tue
7
+    - Wed
8
+    - Thu
9
+    - Fri
10
+    - Sat
11
+    abbr_month_names:
12
+    -
13
+    - Jan
14
+    - Feb
15
+    - Mar
16
+    - Apr
17
+    - May
18
+    - Jun
19
+    - Jul
20
+    - Aug
21
+    - Sep
22
+    - Oct
23
+    - Nov
24
+    - Dec
25
+    day_names:
26
+    - Sunday
27
+    - Monday
28
+    - Tuesday
29
+    - Wednesday
30
+    - Thursday
31
+    - Friday
32
+    - Saturday
33
+    formats:
34
+      default: ! '%Y-%m-%d'
35
+      long: ! '%B %d, %Y'
36
+      short: ! '%b %d'
37
+    month_names:
38
+    -
39
+    - January
40
+    - February
41
+    - March
42
+    - April
43
+    - May
44
+    - June
45
+    - July
46
+    - August
47
+    - September
48
+    - October
49
+    - November
50
+    - December
51
+    order:
52
+    - :year
53
+    - :month
54
+    - :day
55
+  datetime:
56
+    distance_in_words:
57
+      about_x_hours:
58
+        one: about 1 hour
59
+        other: about %{count} hours
60
+      about_x_months:
61
+        one: about 1 month
62
+        other: about %{count} months
63
+      about_x_years:
64
+        one: about 1 year
65
+        other: about %{count} years
66
+      almost_x_years:
67
+        one: almost 1 year
68
+        other: almost %{count} years
69
+      half_a_minute: half a minute
70
+      less_than_x_minutes:
71
+        one: less than a minute
72
+        other: less than %{count} minutes
73
+      less_than_x_seconds:
74
+        one: less than 1 second
75
+        other: less than %{count} seconds
76
+      over_x_years:
77
+        one: over 1 year
78
+        other: over %{count} years
79
+      x_days:
80
+        one: 1 day
81
+        other: ! '%{count} days'
82
+      x_minutes:
83
+        one: 1 minute
84
+        other: ! '%{count} minutes'
85
+      x_months:
86
+        one: 1 month
87
+        other: ! '%{count} months'
88
+      x_seconds:
89
+        one: 1 second
90
+        other: ! '%{count} seconds'
91
+    prompts:
92
+      day: Day
93
+      hour: Hour
94
+      minute: Minute
95
+      month: Month
96
+      second: Seconds
97
+      year: Year
98
+  errors:
99
+    format: ! '%{attribute} %{message}'
100
+    messages:
101
+      accepted: must be accepted
102
+      blank: can't be blank
103
+      present: must be blank
104
+      confirmation: ! "doesn't match %{attribute}"
105
+      empty: can't be empty
106
+      equal_to: must be equal to %{count}
107
+      even: must be even
108
+      exclusion: is reserved
109
+      greater_than: must be greater than %{count}
110
+      greater_than_or_equal_to: must be greater than or equal to %{count}
111
+      inclusion: is not included in the list
112
+      invalid: is invalid
113
+      less_than: must be less than %{count}
114
+      less_than_or_equal_to: must be less than or equal to %{count}
115
+      not_a_number: is not a number
116
+      not_an_integer: must be an integer
117
+      odd: must be odd
118
+      record_invalid: ! 'Validation failed: %{errors}'
119
+      restrict_dependent_destroy:
120
+        one: "Cannot delete record because a dependent %{record} exists"
121
+        many: "Cannot delete record because dependent %{record} exist"
122
+      taken: has already been taken
123
+      too_long:
124
+        one: is too long (maximum is 1 character)
125
+        other: is too long (maximum is %{count} characters)
126
+      too_short:
127
+        one: is too short (minimum is 1 character)
128
+        other: is too short (minimum is %{count} characters)
129
+      wrong_length:
130
+        one: is the wrong length (should be 1 character)
131
+        other: is the wrong length (should be %{count} characters)
132
+      other_than: "must be other than %{count}"
133
+    template:
134
+      body: ! 'There were problems with the following fields:'
135
+      header:
136
+        one: 1 error prohibited this %{model} from being saved
137
+        other: ! '%{count} errors prohibited this %{model} from being saved'
138
+  helpers:
139
+    select:
140
+      prompt: Please select
141
+    submit:
142
+      create: Create %{model}
143
+      submit: Save %{model}
144
+      update: Update %{model}
145
+  number:
146
+    currency:
147
+      format:
148
+        delimiter: ! ','
149
+        format: ! '%u%n'
150
+        precision: 2
151
+        separator: .
152
+        significant: false
153
+        strip_insignificant_zeros: false
154
+        unit: $
155
+    format:
156
+      delimiter: ! ','
157
+      precision: 3
158
+      separator: .
159
+      significant: false
160
+      strip_insignificant_zeros: false
161
+    human:
162
+      decimal_units:
163
+        format: ! '%n %u'
164
+        units:
165
+          billion: Billion
166
+          million: Million
167
+          quadrillion: Quadrillion
168
+          thousand: Thousand
169
+          trillion: Trillion
170
+          unit: ''
171
+      format:
172
+        delimiter: ''
173
+        precision: 3
174
+        significant: true
175
+        strip_insignificant_zeros: true
176
+      storage_units:
177
+        format: ! '%n %u'
178
+        units:
179
+          byte:
180
+            one: Byte
181
+            other: Bytes
182
+          gb: GB
183
+          kb: KB
184
+          mb: MB
185
+          tb: TB
186
+    percentage:
187
+      format:
188
+        delimiter: ''
189
+        format: "%n%"
190
+    precision:
191
+      format:
192
+        delimiter: ''
193
+  support:
194
+    array:
195
+      last_word_connector: ! ', and '
196
+      two_words_connector: ! ' and '
197
+      words_connector: ! ', '
198
+  time:
199
+    am: am
200
+    formats:
201
+      default: ! '%a, %d %b %Y %H:%M:%S %z'
202
+      long: ! '%B %d, %Y %H:%M'
203
+      short: ! '%d %b %H:%M'
204
+    pm: pm
205
+  admin_panel:
206
+    dashboard: Dashboard
207
+    files: Files
208
+    users: Users
209
+    posts: posts
210
+    new_blog_post: New Post
211
+    upload_file: Upload File
212
+    welcome: Welcome back

+ 214 - 0
config/locales/pt-BR.yml

@@ -0,0 +1,214 @@
1
+pt-BR:
2
+  date:
3
+    abbr_day_names:
4
+    - Dom
5
+    - Seg
6
+    - Ter
7
+    - Qua
8
+    - Qui
9
+    - Sex
10
+    - Sáb
11
+    abbr_month_names:
12
+    -
13
+    - Jan
14
+    - Fev
15
+    - Mar
16
+    - Abr
17
+    - Mai
18
+    - Jun
19
+    - Jul
20
+    - Ago
21
+    - Set
22
+    - Out
23
+    - Nov
24
+    - Dez
25
+    day_names:
26
+    - Domingo
27
+    - Segunda
28
+    - Terça
29
+    - Quarta
30
+    - Quinta
31
+    - Sexta
32
+    - Sábado
33
+    formats:
34
+      default: ! '%d/%m/%Y'
35
+      long: ! '%d de %B de %Y'
36
+      short: ! '%d de %B'
37
+    month_names:
38
+    -
39
+    - Janeiro
40
+    - Fevereiro
41
+    - Março
42
+    - Abril
43
+    - Maio
44
+    - Junho
45
+    - Julho
46
+    - Agosto
47
+    - Setembro
48
+    - Outubro
49
+    - Novembro
50
+    - Dezembro
51
+    order:
52
+    - :day
53
+    - :month
54
+    - :year
55
+  datetime:
56
+    distance_in_words:
57
+      about_x_hours:
58
+        one: aproximadamente 1 hora
59
+        other: aproximadamente %{count} horas
60
+      about_x_months:
61
+        one: aproximadamente 1 mês
62
+        other: aproximadamente %{count} meses
63
+      about_x_years:
64
+        one: aproximadamente 1 ano
65
+        other: aproximadamente %{count} anos
66
+      almost_x_years:
67
+        one: quase 1 ano
68
+        other: quase %{count} anos
69
+      half_a_minute: meio minuto
70
+      less_than_x_minutes:
71
+        one: menos de um minuto
72
+        other: menos de %{count} minutos
73
+      less_than_x_seconds:
74
+        one: menos de 1 segundo
75
+        other: menos de %{count} segundos
76
+      over_x_years:
77
+        one: mais de 1 ano
78
+        other: mais de %{count} anos
79
+      x_days:
80
+        one: 1 dia
81
+        other: ! '%{count} dias'
82
+      x_minutes:
83
+        one: 1 minuto
84
+        other: ! '%{count} minutos'
85
+      x_months:
86
+        one: 1 mês
87
+        other: ! '%{count} meses'
88
+      x_seconds:
89
+        one: 1 segundo
90
+        other: ! '%{count} segundos'
91
+    prompts:
92
+      day: Dia
93
+      hour: Hora
94
+      minute: Minuto
95
+      month: Mês
96
+      second: Segundo
97
+      year: Ano
98
+  errors:
99
+    format: ! '%{attribute} %{message}'
100
+    messages:
101
+      accepted: deve ser aceito
102
+      blank: não pode ficar em branco
103
+      present: deve ficar em branco
104
+      confirmation: não é igual a %{attribute}
105
+      empty: não pode ficar vazio
106
+      equal_to: deve ser igual a %{count}
107
+      even: deve ser par
108
+      exclusion: não está disponível
109
+      greater_than: deve ser maior que %{count}
110
+      greater_than_or_equal_to: deve ser maior ou igual a %{count}
111
+      inclusion: não está incluído na lista
112
+      invalid: não é válido
113
+      less_than: deve ser menor que %{count}
114
+      less_than_or_equal_to: deve ser menor ou igual a %{count}
115
+      not_a_number: não é um número
116
+      not_an_integer: não é um número inteiro
117
+      odd: deve ser ímpar
118
+      record_invalid: ! 'A validação falhou: %{errors}'
119
+      restrict_dependent_destroy:
120
+        one: "Não é possível excluir o registro pois existe um %{record} dependente"
121
+        many: "Não é possível excluir o registro pois existem %{record} dependentes"
122
+      taken: já está em uso
123
+      too_long: ! 'é muito longo (máximo: %{count} caracteres)'
124
+      too_short: ! 'é muito curto (mínimo: %{count} caracteres)'
125
+      wrong_length: não possui o tamanho esperado (%{count} caracteres)
126
+      other_than: "deve ser diferente de %{count}"
127
+    template:
128
+      body: ! 'Por favor, verifique o(s) seguinte(s) campo(s):'
129
+      header:
130
+        one: ! 'Não foi possível gravar %{model}: 1 erro'
131
+        other: ! 'Não foi possível gravar %{model}: %{count} erros.'
132
+  helpers:
133
+    select:
134
+      prompt: Por favor selecione
135
+    submit:
136
+      create: Criar %{model}
137
+      submit: Salvar %{model}
138
+      update: Atualizar %{model}
139
+  number:
140
+    currency:
141
+      format:
142
+        delimiter: .
143
+        format: ! '%u %n'
144
+        precision: 2
145
+        separator: ! ','
146
+        significant: false
147
+        strip_insignificant_zeros: false
148
+        unit: R$
149
+    format:
150
+      delimiter: .
151
+      precision: 3
152
+      separator: ! ','
153
+      significant: false
154
+      strip_insignificant_zeros: false
155
+    human:
156
+      decimal_units:
157
+        format: ! '%n %u'
158
+        units:
159
+          billion:
160
+            one: bilhão
161
+            other: bilhões
162
+          million:
163
+            one: milhão
164
+            other: milhões
165
+          quadrillion:
166
+            one: quatrilhão
167
+            other: quatrilhões
168
+          thousand: mil
169
+          trillion:
170
+            one: trilhão
171
+            other: trilhões
172
+          unit: ''
173
+      format:
174
+        delimiter: .
175
+        precision: 2
176
+        significant: true
177
+        strip_insignificant_zeros: true
178
+      storage_units:
179
+        format: ! '%n %u'
180
+        units:
181
+          byte:
182
+            one: Byte
183
+            other: Bytes
184
+          gb: GB
185
+          kb: KB
186
+          mb: MB
187
+          tb: TB
188
+    percentage:
189
+      format:
190
+        delimiter: .
191
+        format: "%n%"
192
+    precision:
193
+      format:
194
+        delimiter: .
195
+  support:
196
+    array:
197
+      last_word_connector: ! ' e '
198
+      two_words_connector: ! ' e '
199
+      words_connector: ! ', '
200
+  time:
201
+    am: ''
202
+    formats:
203
+      default: ! '%a, %d de %B de %Y, %H:%M:%S %z'
204
+      long: ! '%d de %B de %Y, %H:%M'
205
+      short: ! '%d de %B, %H:%M'
206
+    pm: ''
207
+  admin_panel:
208
+    dashboard: Painel
209
+    files: Arquivos
210
+    users: Usuários
211
+    posts: Artigos
212
+    new_blog_post: +
213
+    upload_file: +
214
+    welcome: Bem vindo

+ 1 - 3
readme.md

@@ -7,10 +7,10 @@ A template for creating rails websites that includes the following:
7 7
 * Basic Blog
8 8
 * Admin Panel
9 9
 * SummerNote editor
10
-* Image upload/File System
11 10
 
12 11
 Other features are still under development:
13 12
 
13
+* Image upload/File System
14 14
 * Translation (pt-BR, EN)
15 15
 * Email System
16 16
 * Search System
@@ -22,8 +22,6 @@ Other features are still under development:
22 22
 
23 23
 ## Todo's
24 24
 
25
-* Admin Panel
26
-* Admin Validation
27 25
 * Authentication layout
28 26
 
29 27
 ## Example Websites